package com.suypower.carManage.json;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Vector;

import javax.servlet.ServletException;

import net.sf.json.JSONArray;

import com.jarp.db.DAO;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.suypower.carManage.VO.CombVO;
import com.suypower.carManage.comm.ConstUtil;

public class Get_RepairArea_List extends ActionSupport {

    private String _dc;
    private String query;


    public String getQuery() {
        return query;
    }

    public void setQuery(String query) {
        this.query = query;
    }

    public String get_dc() {
        return _dc;
    }

    public void set_dc(String dc) {
        _dc = dc;
    }

    public String execute() {
        DAO dao = new DAO();
        ArrayList<CombVO> list = new ArrayList<CombVO>();
        String sql = "SELECT * FROM tb_car";
        try {
            Vector v = dao.getDataSet(ConstUtil.DBNAME, sql);
            if (v != null) {
                for (Object obj : v) {
                    Hashtable hash = (Hashtable) obj;
                    CombVO comb = new CombVO();
                    comb.setName((String) hash.get("CODE"));
                    comb.setValue((String) hash.get("ID"));
                    list.add(comb);
                }
                JSONArray json = JSONArray.fromObject(list);
                ActionContext.getContext().put("data", json.toString());
            } else {
                ActionContext.getContext().put("data", "{id:'000',code:'没有数据'}");
            }
        } catch (ServletException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return this.SUCCESS;
    }
}
